const http = require('http');

//爬取内容 1
http.get('http://www.baidu.com',(res) => {
	let html = '';
	res.on("data",(data)=>{
        html += data
    });
    res.on("end",()=>{
        console.log('html1:', html.length);//获取到页面数据
    })
});


//爬取内容 2
const req = http.request({
	hostname: 'www.baidu.com',
	method: 'GET',
	headers: {
		'Content-Type': 'application/json',
	}
}, (res) => {
	let html = '';
	res.on("data",(data)=>{
        html += data;
    });
    res.on("end",()=>{
        console.log('html2:', html.length);//获取到页面数据
    })
});
req.on('error', (e) => {
	console.error(`problem with request: ${e.message}`);
});
req.end();